package socket;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.net.NetSocket;
import io.vertx.core.parsetools.RecordParser;

public class MyVerticle3 extends AbstractVerticle {

	String ip = "10.0.164.26";
	int port = 3001;

	@Override
	public void start() throws Exception {
		EventBus bus = vertx.eventBus();
		vertx.createNetClient().connect(port, ip, asyncResult -> {
			if(asyncResult.succeeded()){
				NetSocket netSocket = asyncResult.result();
				netSocket.handler( buffer ->{

					//TCP粘包拆包处理
					RecordParser parser = RecordParser.newDelimited("\r\n", h -> {
						String s = String.format("设备返回： %s", h.toString());
						System.out.println(s);
					});

					parser.handle(Buffer.buffer(buffer.toString()));
				}).exceptionHandler(Throwable::printStackTrace);
				netSocket.write("\\rSU\\n");
//				netSocket.write("\rSI\n");

			}

		});
	}
}
